package com.lsk.service;

import com.lsk.internalcommon.DTO.OrderInfo;
import com.lsk.internalcommon.DTO.ResponseResult;
import com.lsk.internalcommon.constant.OrderConstants;
import com.lsk.internalcommon.request.OrderRequest;
import com.lsk.mapper.OrderMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    public ResponseResult addOrder(OrderRequest orderRequest){
        OrderInfo info = new OrderInfo();
        BeanUtils.copyProperties(orderRequest,info);
        info.setOrderStatus(OrderConstants.ORDER_START);

        LocalDateTime now = LocalDateTime.now();
        info.setGmtCreate(now);
        info.setGmtModified(now);
        orderMapper.insert(info);
        return ResponseResult.success("新增订单成功");
    }
}
